package com.sunsy.authserver.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunsy.authserver.beans.po.UserTenantRelation;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * (UserTenantRelation)表数据库访问层
 *
 * @author makejava
 * @since 2021-07-20 14:40:45
 */
@Mapper
public interface UserTenantRelationDao extends BaseMapper<UserTenantRelation> {

    @Select("select t.name,uar.user_id from user_tenant_relation uar,tenant t ${ew.customSqlSegment} and uar.tenant_id = t.id ")
    List<Map<String,Object>> getTenantNameByUserId(@Param("ew") Wrapper queryWrapper);

    @Delete("delete from user_tenant_relation where tenant_id = #{tenantId}")
    int deleteByTenantId(String tenantId);

    @Select("select user_id from user_tenant_relation where tenant_id = #{tenantId}")
    List<Long> getUserIdByTenant(String tenantId);

}